package last;

import java.util.ArrayList;
import java.util.Scanner;

class Repo{
	private ArrayList<String> str=new ArrayList<String>();
	private int flag=1;
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public Repo(String items) {
		String[] s=items.split(" ");
		for (int i = 0; i < s.length; i++) {
			str.add(s[i]);
		}
	}
	public int getSize() {
		return str.size();
	}
	public ArrayList<String> getStr() {
		return str;
	}
	public void setStr(ArrayList<String> str) {
		this.str = str;
	}
	public synchronized void task1() {
		if(getSize()>0)
		{
			while(flag==0)
			{
				try
				{
					wait();
				}catch(InterruptedException E)
				{
					E.printStackTrace();
				}
			}
			System.out.println(Thread.currentThread().getName()+" finish "+getStr().get(0));
			getStr().remove(0);
			setFlag(1);
			notify();
		}
	}
	
	public synchronized void task2() {
		if(getSize()>0)
		{
			while(flag==1)
			{
				try
				{
					wait();
				}catch(InterruptedException E)
				{
					E.printStackTrace();
				}
			}
			System.out.println(Thread.currentThread().getName()+" finish "+getStr().get(0));
			getStr().remove(0);
			setFlag(1);
			notify();
		}
	}
}
class worker1 implements Runnable{
	private Repo repo;
	

	public worker1(Repo repo) {
		super();
		this.repo = repo;
	}


	@Override
	public synchronized void run() {
		// TODO Auto-generated method stub
		for (int i = 0; i <repo.getSize(); i++) {
			repo.task1();
		}
		
	}
	
}

class worker2 implements Runnable{
	private Repo repo;
	

	public worker2(Repo repo) {
		super();
		this.repo = repo;
	}


	@Override
	public synchronized void run() {
		// TODO Auto-generated method stub
		for (int i = 0; i <repo.getSize(); i++) {
			repo.task2();
		}
		
	}
	
}
public class Main5 {
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
}
}
